import { request } from '../../utils/request.js'
const state = {
	userInfo: uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : null
}

const getters = {
	userInfo: state => state.userInfo,

}

const mutations = {
	imgCode(state, data) {
		state.userInfo[data.type] = data.url
		console.log(state.userInfo)
	},
	login(state, data) {
		state.userInfo = data
		uni.setStorageSync('userInfo', JSON.stringify(data))
	},
	logout(state) {
		state.userInfo = null
		uni.removeStorageSync('userInfo')
		uni.showToast({
			duration: 1000,
			icon: 'none',
			title: '退出成功！',
			success: () => {
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}, 1000)

			},
		})

	}
}

const actions = {
	setLoginStste({ commit }, data) {
		console.log('setLoginStste')
		console.log(data)
		commit('login', data)
	},
	setLoginOut({ commit }) {
		commit('logout')
	},
	setImgCode({ commit }, data) {
		commit('imgCode', data)
	}
}

export default {
	state,
	getters,
	mutations,
	actions
}

